package com.cx.service.impl;

import com.cx.dto.PageDto;
import com.cx.mapper.LogMessageMapper;
import com.cx.pojo.LogMessage;
import com.cx.service.LogMessageService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description GroupOneproject-IntelliJ IDEA
 * @Author Pyc
 * @Date 2020/5/26 21:08
 * @Version 1.0
 */

@Service
public class LogMessageServiceImpl implements LogMessageService {


    @Autowired
    LogMessageMapper logMessageMapper;


    @Override
    public int insertMessage(LogMessage logMessage) {

        int result = logMessageMapper.insertMessage(logMessage);

        return result;
    }

    @Override
    public List<LogMessage> selectByUid(int uid, PageDto pageDto) {

        List<LogMessage> counts = logMessageMapper.selectByUid(uid);
        if (counts.size()%pageDto.getMaxCount()==0){
            pageDto.setMaxPage(counts.size()/pageDto.getMaxCount());
        }else
            pageDto.setMaxPage(counts.size()/pageDto.getMaxCount()+1);

        PageHelper.startPage(pageDto.getNowPage(),pageDto.getMaxCount());
        List<LogMessage> logMessages = logMessageMapper.selectByUid(uid);
        return logMessages;
    }

    @Override
    public LogMessage selectByid(int id) {

        LogMessage logMessage = logMessageMapper.selectByid(id);
        return logMessage;
    }

    @Override
    public int afterRead(int id) {
        int result = logMessageMapper.updateLogStatus(id);


        return result;
    }

    @Override
    public int delMessage(int id) {

        int result = logMessageMapper.deleteLog(id);
        return result;
    }
}
